# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 231
n 231(None)[self.field_dispatch = [self.select_date, self.select_visible_time_slice, self.select_favorite_list]
self.selected_field = 0
self.start_time, self.end_time = grid.start_time, grid.end_time
self.commit_task = Task(self._commit_changes)
return None
]:
	i: 192(), 205()
	o: 

nname: 205
n 205(None)[self.selected_favorite_pos = int(self.grid.channel_list['index'])
]:
	i: 0(f)
	o: 231()

nname: 192
n 192(None)[self.selected_favorite_pos = -1
]:
	i: 0(t)
	o: 231()

nname: 0
n 0(self.grid.channel_list['index'] is None)[Menu.__init__(self, name='EPG Control Window', choices=[], type='epg_control_window', universe='tv')
self.eventhandler = EpgControlWindowEventHandler(self)
self._getitems_keywords.update({'date': self.get_date, 'time_slice': self.get_time_slice, 'favorite_list': self.get_favorite_list})
self.grid = grid
self.favorites = HiddenRoot().get_child('TV Favorites', self.grid).browse()
self.acl = TVRootItem().get_acl(self.grid)
]:
	i: 
	o: 192(t), 205(f)

nname: 0
n 0(None)[Menu.__init__(self, name='EPG Control Window', choices=[], type='epg_control_window', universe='tv')
self.eventhandler = EpgControlWindowEventHandler(self)
self._getitems_keywords.update({'date': self.get_date, 'time_slice': self.get_time_slice, 'favorite_list': self.get_favorite_list})
self.grid = grid
self.favorites = HiddenRoot().get_child('TV Favorites', self.grid).browse()
self.acl = TVRootItem().get_acl(self.grid)
if self.grid.channel_list['index'] is None:
	self.selected_favorite_pos = -1
else:
	self.selected_favorite_pos = int(self.grid.channel_list['index'])
self.field_dispatch = [self.select_date, self.select_visible_time_slice, self.select_favorite_list]
self.selected_field = 0
self.start_time, self.end_time = grid.start_time, grid.end_time
self.commit_task = Task(self._commit_changes)
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7726dac>}
nname: 101
n 101(None)[]:
	i: 45(), 100()
	o: 

nname: 100
n 100(None)[]:
	i: 42(f)
	o: 101()

nname: 45
n 45(None)[self.selected_field += value
field_name = self.fields[self.selected_field]
louie_send('on_control_select_%s' % field_name, sender=self)
]:
	i: 42(t)
	o: 101()

nname: 42
n 42(0 <= self.selected_field + value)[]:
	i: 21(), 40()
	o: 45(t), 100(f)

nname: 40
n 40(None)[self.selected_field + value
]:
	i: 0(f)
	o: 42()

nname: 21
n 21(None)[]:
	i: 0(t)
	o: 42()

nname: 0
n 0(0 <= self.selected_field + value)[]:
	i: 
	o: 21(t), 40(f)

nname: 101
n 101(None)[]:
	i: 0()
	o: 

nname: 0
n 0(None)[if 0 <= self.selected_field + value:
	pass
else:
	self.selected_field + value
if 0 <= self.selected_field + value:
	self.selected_field += value
	field_name = self.fields[self.selected_field]
	louie_send('on_control_select_%s' % field_name, sender=self)
]:
	i: 
	o: 101()

nname: 0
n 0(None)[if 0 <= self.selected_field + value:
	pass
else:
	self.selected_field + value
if 0 <= self.selected_field + value:
	self.selected_field += value
	field_name = self.fields[self.selected_field]
	louie_send('on_control_select_%s' % field_name, sender=self)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb772664c>}
nname: 0
n 0(None)[self.field_dispatch[self.selected_field](value)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719e8c>}
nname: 103
n 103(None)[]:
	i: 66(), 102()
	o: 

nname: 102
n 102(None)[]:
	i: 48(f)
	o: 103()

nname: 66
n 66(None)[grid.set_boundaries(self.start_time, self.end_time)
grid.select_current_program()
]:
	i: 48(t)
	o: 103()

nname: 48
n 48(self.start_time != grid.start_time)[]:
	i: 27(), 47()
	o: 66(t), 102(f)

nname: 47
n 47(None)[]:
	i: 0(f)
	o: 48()

nname: 27
n 27(None)[grid.set_channel_list(self.selected_favorite_list)
]:
	i: 0(t)
	o: 48()

nname: 0
n 0(self.selected_favorite_list != grid.channel_list)[grid = self.grid
]:
	i: 
	o: 27(t), 47(f)

nname: 103
n 103(None)[]:
	i: 0()
	o: 

nname: 0
n 0(None)[grid = self.grid
if self.selected_favorite_list != grid.channel_list:
	grid.set_channel_list(self.selected_favorite_list)
if self.start_time != grid.start_time:
	grid.set_boundaries(self.start_time, self.end_time)
	grid.select_current_program()
]:
	i: 
	o: 103()

nname: 0
n 0(None)[grid = self.grid
if self.selected_favorite_list != grid.channel_list:
	grid.set_channel_list(self.selected_favorite_list)
if self.start_time != grid.start_time:
	grid.set_boundaries(self.start_time, self.end_time)
	grid.select_current_program()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7726ccc>}
nname: 0
n 0(None)[self.grid.display_info_banner()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719e0c>}
nname: 0
n 0(None)[return Menu.show(self, False)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719cac>}
nname: 0
n 0(None)[return ts.get_epg_day(self.start_time).strftime(get_date_format())
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719ecc>}
nname: 0
n 0(None)[slice_id = ts.get_visible_slice_id(self.start_time)
return ts.NAMES[slice_id]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719d2c>}
nname: 0
n 0(None)[return self.selected_favorite_list.name
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719c8c>}
nname: 6
n 6(None)[__doc__ = 'EPG control window.'
fields = ['date', 'time_slice', 'favorite_list']
def __init__(self, grid):
	Menu.__init__(self, name='EPG Control Window', choices=[], type='epg_control_window', universe='tv')
	self.eventhandler = EpgControlWindowEventHandler(self)
	self._getitems_keywords.update({'date': self.get_date, 'time_slice': self.get_time_slice, 'favorite_list': self.get_favorite_list})
	self.grid = grid
	self.favorites = HiddenRoot().get_child('TV Favorites', self.grid).browse()
	self.acl = TVRootItem().get_acl(self.grid)
	if self.grid.channel_list['index'] is None:
		self.selected_favorite_pos = -1
	else:
		self.selected_favorite_pos = int(self.grid.channel_list['index'])
	self.field_dispatch = [self.select_date, self.select_visible_time_slice, self.select_favorite_list]
	self.selected_field = 0
	self.start_time, self.end_time = grid.start_time, grid.end_time
	self.commit_task = Task(self._commit_changes)
	return None

def select_field(self, value):
	if 0 <= self.selected_field + value:
		pass
	else:
		self.selected_field + value
	if 0 <= self.selected_field + value:
		self.selected_field += value
		field_name = self.fields[self.selected_field]
		louie_send('on_control_select_%s' % field_name, sender=self)

def select_value(self, value):
	self.field_dispatch[self.selected_field](value)

select_date = selective_gui_updater('date')()
select_visible_time_slice = selective_gui_updater('time_slice', 'date')()
selected_favorite_list = property()
select_favorite_list = selective_gui_updater('favorite_list')()
def _commit_changes(self):
	grid = self.grid
	if self.selected_favorite_list != grid.channel_list:
		grid.set_channel_list(self.selected_favorite_list)
	if self.start_time != grid.start_time:
		grid.set_boundaries(self.start_time, self.end_time)
		grid.select_current_program()

def display_info_banner(self):
	self.grid.display_info_banner()

def show(self):
	return Menu.show(self, False)

def get_date(self):
	return ts.get_epg_day(self.start_time).strftime(get_date_format())

def get_time_slice(self):
	slice_id = ts.get_visible_slice_id(self.start_time)
	return ts.NAMES[slice_id]

def get_favorite_list(self):
	return self.selected_favorite_list.name

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb771972c>}
nname: 408
n 408(None)[extra_info.append(Item(name='maturity', type_=maturity, menu=self))
self.set_items(extra_info, 'main_list', -1)
return None
]:
	i: 381(), 401()
	o: 

nname: 401
n 401(None)[]:
	i: 353(f)
	o: 408()

nname: 381
n 381(None)[]:
	i: 353(t)
	o: 408()

nname: 353
n 353(maturity_key is not None)[del _[2]
for extra_info in program.EXTRA_INFO_FIELDS:
]:
	i: 260(AF), 349()
	o: 381(t), 401(f)

nname: 349
n 349(None)[]:
	i: 286(f), 311()
	o: 353()

nname: 311
n 311(None)[continue
]:
	i: 286(t)
	o: 349()

nname: 286
n 286(int(program[key]))[]:
	i: 260(for)
	o: 311(t), 349(f)

nname: 260
n 260(None)[self.selected_page = 0
]:
	i: 235(), 247()
	o: 286(for), 353(AF)

nname: 247
n 247(None)[self.pages = ['']
]:
	i: 0(f)
	o: 260()

nname: 235
n 235(None)[del _[1]
for self.pages in xrange(0, len(description), self.PAGE_SIZE):
]:
	i: 172(AF), 208()
	o: 260()

nname: 208
n 208(None)[for start in xrange(0, len(description), self.PAGE_SIZE):
]:
	i: 172(for)
	o: 235()

nname: 172
n 172(None)[]:
	i: 0(t)
	o: 208(for), 235(AF)

nname: 0
n 0(description)[Menu.__init__(self, name='EPG Info Banner', choices=[], type='epg_info_banner')
self.eventhandler = EpgInfoBannerEventHandler(self)
self._getitems_keywords.update({'name': self.get_name, 'start_time': self.get_start_time, 'end_time': self.get_end_time, 'duration': self.get_duration, 'content_type': self.get_content_type, 'description': self.get_description})
self.program = program
description = self.program.short_description + '\n' + program.description
]:
	i: 
	o: 172(t), 247(f)

nname: 353
n 353(None)[del _[2]
for extra_info in program.EXTRA_INFO_FIELDS:
if maturity_key is not None:
	pass
extra_info.append(Item(name='maturity', type_=maturity, menu=self))
self.set_items(extra_info, 'main_list', -1)
return None
]:
	i: 260(AF), 286()
	o: 

nname: 286
n 286(None)[if int(program[key]):
	continue
]:
	i: 260(for)
	o: 353()

nname: 260
n 260(None)[self.selected_page = 0
]:
	i: 235(), 247()
	o: 286(for), 353(AF)

nname: 247
n 247(None)[self.pages = ['']
]:
	i: 0(f)
	o: 260()

nname: 235
n 235(None)[del _[1]
for self.pages in xrange(0, len(description), self.PAGE_SIZE):
]:
	i: 172(AF), 208()
	o: 260()

nname: 208
n 208(None)[for start in xrange(0, len(description), self.PAGE_SIZE):
]:
	i: 172(for)
	o: 235()

nname: 172
n 172(None)[]:
	i: 0(t)
	o: 208(for), 235(AF)

nname: 0
n 0(description)[Menu.__init__(self, name='EPG Info Banner', choices=[], type='epg_info_banner')
self.eventhandler = EpgInfoBannerEventHandler(self)
self._getitems_keywords.update({'name': self.get_name, 'start_time': self.get_start_time, 'end_time': self.get_end_time, 'duration': self.get_duration, 'content_type': self.get_content_type, 'description': self.get_description})
self.program = program
description = self.program.short_description + '\n' + program.description
]:
	i: 
	o: 172(t), 247(f)

self.nodes: {0: <unpyclib.structure.node instance at 0xb77202ec>, 260: <unpyclib.structure.node instance at 0xb7720a2c>, 353: <unpyclib.structure.node instance at 0xb772af2c>, 235: <unpyclib.structure.node instance at 0xb772028c>, 172: <unpyclib.structure.node instance at 0xb772004c>, 208: <unpyclib.structure.node instance at 0xb772024c>, 247: <unpyclib.structure.node instance at 0xb77203cc>, 286: <unpyclib.structure.node instance at 0xb772afec>}
nname: 0
n 0(None)[return Menu.show(self, False)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719a2c>}
nname: 0
n 0(None)[return self.program.name
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb77195cc>}
nname: 0
n 0(None)[return seconds_to_hhmm(self.program.start_time)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb7719a8c>}
nname: 0
n 0(None)[return seconds_to_hhmm(self.program.end_time)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb771958c>}
nname: 0
n 0(None)[return seconds_to_hhmm_utc(self.program.duration)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb771960c>}
nname: 0
n 0(None)[return self.program.content_type
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb77196cc>}
nname: 0
n 0(None)[return self.program.short_description
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb771950c>}
nname: 0
n 0(None)[return self.pages[self.selected_page]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb771958c>}
nname: 6
n 6(None)[__doc__ = 'Full information banner for a program.'
PAGE_SIZE = 900
def __init__(self, program):
	Menu.__init__(self, name='EPG Info Banner', choices=[], type='epg_info_banner')
	self.eventhandler = EpgInfoBannerEventHandler(self)
	self._getitems_keywords.update({'name': self.get_name, 'start_time': self.get_start_time, 'end_time': self.get_end_time, 'duration': self.get_duration, 'content_type': self.get_content_type, 'description': self.get_description})
	self.program = program
	description = self.program.short_description + '\n' + program.description

select_page = selective_gui_updater('description')()
def show(self):
	return Menu.show(self, False)

def get_name(self):
	return self.program.name

def get_start_time(self):
	return seconds_to_hhmm(self.program.start_time)

def get_end_time(self):
	return seconds_to_hhmm(self.program.end_time)

def get_duration(self):
	return seconds_to_hhmm_utc(self.program.duration)

def get_content_type(self):
	return self.program.content_type

def get_short_description(self):
	return self.program.short_description

def get_description(self):
	return self.pages[self.selected_page]

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb7797ecc>}
nname: 0
n 0(None)[from __future__ import absolute_import
from datetime import timedelta
from peewee.messages import send as louie_send
from peewee.formatters import seconds_to_hhmm, seconds_to_hhmm_utc
from peewee.notifier import Task
from pygui.config import HMI_TV
from pygui.eventmanager.menus import EpgControlWindowEventHandler, EpgInfoBannerEventHandler
from pygui.facilities.l10n import get_date_format
from pygui.facilities import timeslices as ts
from pygui.item.core import Item
from pygui.item.mediaitem import HiddenRoot, TVRootItem
from pygui.menu import selective_gui_updater
from ..core import Menu
class EpgControlWindowMenu(Menu):
	__doc__ = 'EPG control window.'
	fields = ['date', 'time_slice', 'favorite_list']
	def __init__(self, grid):
		Menu.__init__(self, name='EPG Control Window', choices=[], type='epg_control_window', universe='tv')
		self.eventhandler = EpgControlWindowEventHandler(self)
		self._getitems_keywords.update({'date': self.get_date, 'time_slice': self.get_time_slice, 'favorite_list': self.get_favorite_list})
		self.grid = grid
		self.favorites = HiddenRoot().get_child('TV Favorites', self.grid).browse()
		self.acl = TVRootItem().get_acl(self.grid)
		if self.grid.channel_list['index'] is None:
			self.selected_favorite_pos = -1
		else:
			self.selected_favorite_pos = int(self.grid.channel_list['index'])
		self.field_dispatch = [self.select_date, self.select_visible_time_slice, self.select_favorite_list]
		self.selected_field = 0
		self.start_time, self.end_time = grid.start_time, grid.end_time
		self.commit_task = Task(self._commit_changes)
		return None

	def select_field(self, value):
		if 0 <= self.selected_field + value:
			pass
		else:
			self.selected_field + value
		if 0 <= self.selected_field + value:
			self.selected_field += value
			field_name = self.fields[self.selected_field]
			louie_send('on_control_select_%s' % field_name, sender=self)

	def select_value(self, value):
		self.field_dispatch[self.selected_field](value)

	select_date = selective_gui_updater('date')()
	select_visible_time_slice = selective_gui_updater('time_slice', 'date')()
	selected_favorite_list = property()
	select_favorite_list = selective_gui_updater('favorite_list')()
	def _commit_changes(self):
		grid = self.grid
		if self.selected_favorite_list != grid.channel_list:
			grid.set_channel_list(self.selected_favorite_list)
		if self.start_time != grid.start_time:
			grid.set_boundaries(self.start_time, self.end_time)
			grid.select_current_program()

	def display_info_banner(self):
		self.grid.display_info_banner()

	def show(self):
		return Menu.show(self, False)

	def get_date(self):
		return ts.get_epg_day(self.start_time).strftime(get_date_format())

	def get_time_slice(self):
		slice_id = ts.get_visible_slice_id(self.start_time)
		return ts.NAMES[slice_id]

	def get_favorite_list(self):
		return self.selected_favorite_list.name



class EpgInfoBanner(Menu):
	__doc__ = 'Full information banner for a program.'
	PAGE_SIZE = 900
	def __init__(self, program):
		Menu.__init__(self, name='EPG Info Banner', choices=[], type='epg_info_banner')
		self.eventhandler = EpgInfoBannerEventHandler(self)
		self._getitems_keywords.update({'name': self.get_name, 'start_time': self.get_start_time, 'end_time': self.get_end_time, 'duration': self.get_duration, 'content_type': self.get_content_type, 'description': self.get_description})
		self.program = program
		description = self.program.short_description + '\n' + program.description

	select_page = selective_gui_updater('description')()
	def show(self):
		return Menu.show(self, False)

	def get_name(self):
		return self.program.name

	def get_start_time(self):
		return seconds_to_hhmm(self.program.start_time)

	def get_end_time(self):
		return seconds_to_hhmm(self.program.end_time)

	def get_duration(self):
		return seconds_to_hhmm_utc(self.program.duration)

	def get_content_type(self):
		return self.program.content_type

	def get_short_description(self):
		return self.program.short_description

	def get_description(self):
		return self.pages[self.selected_page]



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb778f78c>}
from __future__ import absolute_import
from datetime import timedelta
from peewee.messages import send as louie_send
from peewee.formatters import seconds_to_hhmm, seconds_to_hhmm_utc
from peewee.notifier import Task
from pygui.config import HMI_TV
from pygui.eventmanager.menus import EpgControlWindowEventHandler, EpgInfoBannerEventHandler
from pygui.facilities.l10n import get_date_format
from pygui.facilities import timeslices as ts
from pygui.item.core import Item
from pygui.item.mediaitem import HiddenRoot, TVRootItem
from pygui.menu import selective_gui_updater
from ..core import Menu
class EpgControlWindowMenu(Menu):
	__doc__ = 'EPG control window.'
	fields = ['date', 'time_slice', 'favorite_list']
	def __init__(self, grid):
		Menu.__init__(self, name='EPG Control Window', choices=[], type='epg_control_window', universe='tv')
		self.eventhandler = EpgControlWindowEventHandler(self)
		self._getitems_keywords.update({'date': self.get_date, 'time_slice': self.get_time_slice, 'favorite_list': self.get_favorite_list})
		self.grid = grid
		self.favorites = HiddenRoot().get_child('TV Favorites', self.grid).browse()
		self.acl = TVRootItem().get_acl(self.grid)
		if self.grid.channel_list['index'] is None:
			self.selected_favorite_pos = -1
		else:
			self.selected_favorite_pos = int(self.grid.channel_list['index'])
		self.field_dispatch = [self.select_date, self.select_visible_time_slice, self.select_favorite_list]
		self.selected_field = 0
		self.start_time, self.end_time = grid.start_time, grid.end_time
		self.commit_task = Task(self._commit_changes)
		return None

	def select_field(self, value):
		if 0 <= self.selected_field + value:
			pass
		else:
			self.selected_field + value
		if 0 <= self.selected_field + value:
			self.selected_field += value
			field_name = self.fields[self.selected_field]
			louie_send('on_control_select_%s' % field_name, sender=self)

	def select_value(self, value):
		self.field_dispatch[self.selected_field](value)

	select_date = selective_gui_updater('date')()
	select_visible_time_slice = selective_gui_updater('time_slice', 'date')()
	selected_favorite_list = property()
	select_favorite_list = selective_gui_updater('favorite_list')()
	def _commit_changes(self):
		grid = self.grid
		if self.selected_favorite_list != grid.channel_list:
			grid.set_channel_list(self.selected_favorite_list)
		if self.start_time != grid.start_time:
			grid.set_boundaries(self.start_time, self.end_time)
			grid.select_current_program()

	def display_info_banner(self):
		self.grid.display_info_banner()

	def show(self):
		return Menu.show(self, False)

	def get_date(self):
		return ts.get_epg_day(self.start_time).strftime(get_date_format())

	def get_time_slice(self):
		slice_id = ts.get_visible_slice_id(self.start_time)
		return ts.NAMES[slice_id]

	def get_favorite_list(self):
		return self.selected_favorite_list.name



class EpgInfoBanner(Menu):
	__doc__ = 'Full information banner for a program.'
	PAGE_SIZE = 900
	def __init__(self, program):
		Menu.__init__(self, name='EPG Info Banner', choices=[], type='epg_info_banner')
		self.eventhandler = EpgInfoBannerEventHandler(self)
		self._getitems_keywords.update({'name': self.get_name, 'start_time': self.get_start_time, 'end_time': self.get_end_time, 'duration': self.get_duration, 'content_type': self.get_content_type, 'description': self.get_description})
		self.program = program
		description = self.program.short_description + '\n' + program.description

	select_page = selective_gui_updater('description')()
	def show(self):
		return Menu.show(self, False)

	def get_name(self):
		return self.program.name

	def get_start_time(self):
		return seconds_to_hhmm(self.program.start_time)

	def get_end_time(self):
		return seconds_to_hhmm(self.program.end_time)

	def get_duration(self):
		return seconds_to_hhmm_utc(self.program.duration)

	def get_content_type(self):
		return self.program.content_type

	def get_short_description(self):
		return self.program.short_description

	def get_description(self):
		return self.pages[self.selected_page]



